package org.desktop.web.shared.domain.entities;

import java.io.Serializable;

import javax.persistence.*;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
import com.fasterxml.jackson.annotation.JsonInclude.Include;

import java.util.List;


/**
 * The persistent class for the ROLES database table.
 * 
 */
@Entity
@Table(name="ROLES")
@NamedQuery(name="Role.findAll", query="SELECT r FROM Role r")
@JsonAutoDetect(fieldVisibility=Visibility.ANY)
@JsonIgnoreProperties(value={"functions","roles","subFunctions"})
@JsonInclude(Include.NON_NULL)
public class Role implements Serializable, com.google.gwt.user.client.rpc.IsSerializable {
	private static final long serialVersionUID = 1L;
	private int id;
	private String codRole;
	private String descRole;
	private List<Function> functions;
	private List<SubFunction> subFunctions;
	private List<User> users;

	public Role() {
	}


	@Id
	@Column(unique=true, nullable=false)
	public int getId() {
		return this.id;
	}

	public void setId(int id) {
		this.id = id;
	}


	@Column(name="COD_ROLE", length=5)
	public String getCodRole() {
		return this.codRole;
	}

	public void setCodRole(String codRole) {
		this.codRole = codRole;
	}


	@Column(name="DESC_ROLE", length=45)
	public String getDescRole() {
		return this.descRole;
	}

	public void setDescRole(String descRole) {
		this.descRole = descRole;
	}


	//bi-directional many-to-many association to Function
	@ManyToMany(mappedBy="roles")
	public List<Function> getFunctions() {
		return this.functions;
	}

	public void setFunctions(List<Function> functions) {
		this.functions = functions;
	}


	//bi-directional many-to-many association to SubFunction
	@ManyToMany(mappedBy="roles")
	public List<SubFunction> getSubFunctions() {
		return this.subFunctions;
	}

	public void setSubFunctions(List<SubFunction> subFunctions) {
		this.subFunctions = subFunctions;
	}


	//bi-directional many-to-one association to User
	@OneToMany(mappedBy="role")
	public List<User> getUsers() {
		return this.users;
	}

	public void setUsers(List<User> users) {
		this.users = users;
	}

	public User addUser(User user) {
		getUsers().add(user);
		user.setRole(this);

		return user;
	}

	public User removeUser(User user) {
		getUsers().remove(user);
		user.setRole(null);

		return user;
	}

}